package com.alone.jpa.query.ext;

import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.ParameterRegistry;
import org.hibernate.query.criteria.internal.compile.RenderingContext;
import org.hibernate.query.criteria.internal.predicate.AbstractSimplePredicate;

/**
 * 拼接hql片段的Predicate
 *
 * @author Alone
 */
public class HqlSegmentPredicate extends AbstractSimplePredicate {

    private final String applyHql;

    public HqlSegmentPredicate(CriteriaBuilderImpl criteriaBuilder, String applyHql) {
        super(criteriaBuilder);
        this.applyHql = applyHql;
    }

    @Override
    public void registerParameters(ParameterRegistry parameterRegistry) {
        // nothing to do here
    }

    @Override
    public String render(boolean isNegated, RenderingContext renderingContext) {
        if (isNegated) {
            throw new UnsupportedOperationException("hql segment render is not support negated");
        }
        return applyHql;
    }
}
